package com.zkr.kfkq.conterllor;


import com.zkr.kfkq.model.KFKQAddVo;
import com.zkr.kfkq.model.KFKQSelectVo;
import com.zkr.kfkq.model.KFKQUpdateStatusVo;
import com.zkr.kfkq.model.KFKQUpdateVo;
import com.zkr.kfkq.service.KFKQService;
import com.zkr.util.ResultBuilderVo;
import com.zkr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by lenovo on 2021/1/13.
 */
@RestController
@CrossOrigin
public class KFKQConterllor {

    @Autowired
    private KFKQService kfkqService;


    /**
     * 分页
     * @param
     * @return
     */
    @PostMapping("storageSection/queryPage")
    public ResultVo queryPage(@RequestBody KFKQSelectVo kfkqSelectVo) {
        return kfkqService.queryPage(kfkqSelectVo);
    }


    /**
     * 添加
     */
   @PostMapping("storageSection/add")
    public ResultVo add(@RequestBody @Valid KFKQAddVo kfkqAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfkqService.add(kfkqAddVo);
    }


    /**
     * 修改启用禁用接口
     * @param
     * @param bindingResult
     * @return
     */
    @PostMapping("storageSection/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid KFKQUpdateStatusVo kfkqUpdateStatusVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfkqService.updateStatus(kfkqUpdateStatusVo);
    }

    /**
     * 查询库房编码下的信息
     */
    @GetMapping("storageSection/queryWareHouse")
    public  ResultVo queryCode(){
        return kfkqService.queryCode();
    }

    /**
     *查看
     */
    @GetMapping("storageSection/queryStorageSectionById")
    public ResultVo query(Integer id){
        return kfkqService.query(id);
    }

    /**
     * 查询库区属性
     */
    @GetMapping("storageSection/queryBusinessAttribute")
    public ResultVo queryEulogy(){
        return kfkqService.queryEulogy();
    }

    /**
     * 修改
     */
    @PostMapping("storageSection/update")
    public ResultVo update(@RequestBody @Valid KFKQUpdateVo kfkqUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfkqService.update(kfkqUpdateVo);
    }

}








